<?php
class TeacherController  extends AdminBaseController{
	public function lists (){
		$teacher = HttpServerManager::getTeacherServer();
		$order_by = 'order by pxh desc ';
		if(isset($_GET['pxh_flg'])&&!empty($_GET['pxh_flg'])){
			if($_GET['pxh_flg']=='sort_asc'){
				$order_by = 'order by pxh asc ';
			}
		}
		$data = $teacher->pagingBySearch($_GET,$order_by);
		
		$list = $data['list'];
		$data['list'] =$list;
		
		//页面标签
		$data['nationality'] = Common::_t('nationality');
		$data['teacher_status'] = Common::_t('teacher_status');
		$data['sex']=Common::_t('sex');
		$data['network_stat']= Common::_t('network_stat');

		$data['sexOption']  = page_modifier_options($data['sex'],Common::getGetStrValue('sex'));
		$data['contract_category']=Common::_t('contract_category');
		$data['statusOption']  = page_modifier_options($data['teacher_status'],Common::getGetStrValue('status'));
		$data['contractCategoryOption']  = page_modifier_options($data['contract_category'],Common::getGetStrValue('contract_category'));
		return $data;
	}
	
	public function openClasslist(){
		if(!isset($_GET['start_book_time'])){
			$defaultBookTime = Common::getDefaultBeforeOpenTime();;
			$_GET['start_book_time'] = $defaultBookTime;
			$_GET['book_date'] = date('Y-m-d');
			
		}else{
			$defaultBookTime = common::getGetStrValue('start_book_time'); 
		}

		$teacher = HttpServerManager::getTeacherServer();
		$where=array();
		$where['teacher_openclass_status']=$_GET['teacher_openclass_status'];
		$where['name']=$_GET['name'];
		$where['teacher_no']=$_GET['teacher_no'];
		$where['start_book_time']=$_GET['start_book_time'];
		$where['book_date']=strtotime($_GET['book_date']);
		$where['confirm_status']=TEACHER_STATUS_CONFIRMED;
		$data = $teacher->pagingTeacherOpenClassBySearch($where,"",30);
		$book_course_pair = array();
		$times_pair = Common::getTimes();
		if(!empty($data)){
			$teacher_class_id_list = Common::array_value_list($data['list'],'teacher_class_id');
			if(!empty($teacher_class_id_list)){
				$teacher_class_id_list_str = implode(',',$teacher_class_id_list);
				$book_course_list = HttpDaoManager::getBookCourseDao()->getBookCourseListByTeacherCLassidList($teacher_class_id_list_str);	
				foreach($book_course_list as $key=>$value){
					$book_course_pair[$value['teacher_class_id']] = $value['id'];
				}	
			}
		}
		
		foreach($data['list'] as $key=>$value){
			$data['list'][$key]['open_time_name'] =$times_pair[$value['open_time']]['name'].'-'.$times_pair[$value['open_time']]['nextName'];
			if($value['status']!=TEACHER_CLASS_STATUS_NOTBOOKING){
				$data['list'][$key]['book_course_id'] = $book_course_pair[$value['teacher_class_id']];
			}
		}
		
		$data['booktime_pair'] = Common::getTimesPairsArray();
		$data['bookTimeOptions'] = page_modifier_options($data['booktime_pair'],$defaultBookTime);
		
		$list = $data['list'];
		$data['list'] =$list;
		
		$data['teacher_openclass_status_pair'] = Common::_t('teacher_openclass_status');
		$data['teacherOpenclassStatusOptions'] = page_modifier_options_ext($data['teacher_openclass_status_pair'],common::getGetStrValue('teacher_openclass_status'));
		
		return $data;		
	}
	
	public function add(){
		$data = array();
		if (!empty($_GET['id'])){
			$data = HttpDaoManager::getTeacherDao()->get($_GET['id']);
			$data['good_course'] = str_replace('|','',$data['good_course']);
			$data['good_course'] = explode(',',$data['good_course']);
		}else{
			$sysKey = 'TEA_NO';
			$key_info  =  HttpDaoManager::getSysConfigDao()->getBySyskey($sysKey);
			$seed_no = $key_info['sys_value'];	
			$data['serial_number'] = Common::executeSerialNumber('T','9',$seed_no);
			$sys_update = array();
			$sys_update['sys_value']=$seed_no+1;
			$sys_id = $key_info['id'];
			$key_info  =  HttpDaoManager::getSysConfigDao()->update($sys_update,$sys_id);				
		}
		$english_level = Common::_t('english_level');
		
		$educationExperience = Common::_t('education_experience');
		$educationExperienceOption = page_modifier_options($educationExperience,getStr($data, 'education_experience'));
		$data['educationExperienceOption'] = $educationExperienceOption;
		
		$educationExperience = Common::_t('education_experience');
		$realEducationExperienceOption = page_modifier_options($educationExperience,getStr($data, 'real_education_experience'));
		$data['realEducationExperienceOption'] = $realEducationExperienceOption;

		$data['course_types'] = Common::_t('course_type');
		
		$status=Common::_t('teacher_status');
		$data['statusOption']  = page_modifier_options($status,getStr($data,'status'));
		
		$contract_category=Common::_t('contract_category');
		$data['contractCategoryOption']  = page_modifier_options($contract_category,getStr($data,'contract_category'));
		
		
		$nationality=Common::_t('nationality');
		$data['nationalityOption']  = page_modifier_options($nationality,getStr($data,'nationality'));
		
		$sex=Common::_t('sex');
		$data['sexOption']  = page_modifier_options($sex,getStr($data,'sex'));
		
		$skypeStatusOption = page_modifier_options($skypeStatus,getStr($data, 'skype_status'));
		$data['skypeStatusOption'] = $skypeStatusOption;
		
		
		$skypeStatus =  Common::_t('skype_status');
		$skypeStatusOption = page_modifier_options($skypeStatus,getStr($data, 'skype_status'));
		$data['skypeStatusOption'] = $skypeStatusOption;
		
		$qqStatus =  Common::_t('qq_status');
		$qqStatusOption = page_modifier_options($skypeStatus,getStr($data, 'qq_status'));
		$data['qqStatusOption'] = $qqStatusOption;
		
		$data['teacherLevelOption'] = page_modifier_options($english_level,common::getStrValue($data, 'english_level'));
		$introduce = Common::getStrValue($data,'introduce');


		$network_stat=Common::_t('network_stat');
		$data['networkStatOption']  = page_modifier_options($network_stat,getStr($data,'network_stat'));
				
		
		$level_list = HttpDaoManager::getLevelDao()->searchList();
		$level_pair = array();
		foreach($level_list as $k=>$v){
			if(isset($v['id'])){
				//$level_pair[$v['id']]='Level'.'-'.$v['level'].':'.$v['subject'];
				$level_pair[$v['id']]='Level'.'-'.$v['level'];
			}
		}		
		
		unset($level_list);
		$data['teachLevelOption'] = page_modifier_options($level_pair,common::getStrValue($data, 'teach_level'));
		
		$ueditor = ClassManager::getUeditor();
		$introduce_chinese_content = Common::getStrValue($data, 'introduce_chinese');
		$data['ueditor_introduce_chinese'] = $ueditor->ueditor().$ueditor->ueditors_2('introduce_chinese',$introduce_chinese_content);

		$introduce_english_content = Common::getStrValue($data, 'introduce_english');
		$data['ueditor_introduce_english'] = $ueditor->ueditors_2('introduce_english',$introduce_english_content);

		$resume = Common::getStrValue($data, 'resume');
		$data['ueditor_resume'] = $ueditor->ueditors_2('resume',$resume);

		$english_resume = Common::getStrValue($data, 'english_resume');
		$data['ueditor_english_resume'] =$ueditor->ueditors_2('enlish_resume',$english_resume);
		
		$data['employees'] = HttpDaoManager::getEmployeesDao()->searchList(); 
		//页面标签
		$data['id'] = Common::getGetStrValue('id');
		
		return $data;
	}
	public function subAdd(){
		$tmp =HttpServerManager::getTeacherServer()->add($_POST);
		if ($tmp ===true){
			ClassManager::getToos()->msgbox(Common::_t('data_insert_success'));
		}
		else{
			$msssage = Common::_t('control_messsage');
			$msgbox  = array(
				1=>$message['message_1']
			);
			ClassManager::getToos()->msgbox($msgbox[$tmp]);
		}	
	}
	public function subUpdate(){
		HttpServerManager::getTeacherServer()->update($_POST, $_POST['id']);
		ClassManager::getToos()->msgbox(Common::_t('data_edit_success'),'teacher_lists.html');
	}
	
	public function subUpdatePxh(){
		HttpServerManager::getTeacherServer()->update($_POST, $_POST['id']);
		$result = array();
		$result['success']='success';
		exit(json_encode($result));
	}
	
	public function delete(){
		HttpServerManager::getTeacherServer()->deleteBatchByid($_GET['id']);
		ClassManager::getToos()->msgbox(Common::_t('data_del_success'));
	}

	public function updateManagement(){
		$data['batchId']  = implode(',',$_GET['id']);
		$data['employees'] = HttpDaoManager::getEmployeesDao()->searchList();
		return $data;
	}
	
	public function subUpdateManagement(){
		HttpDaoManager::getTeacherDao()->batchUpdateManagement($_POST['employees_id'], $_POST['batchId']);
		ClassManager::getToos()->msgbox(Common::_t('data_edit_success'),'teacher_lists.html');
	}
	public function managementInfo(){
		return HttpDaoManager::getEmployeesDao()->get($_GET['employeesId']);
	}
	public function info(){
		$data =  HttpServerManager::getTeacherServer()->info();
		if ($data ==1){
			$msssage = Common::_t('control_messsage');
			ClassManager::getToos()->msgbox($msssage['message_2']);
		}
		$good_course = str_replace('|','',$data['good_course']);
		$good_course = explode(',',$good_course);
		$tmp=array();
		$course_type = Common::_t("course_type");
		foreach ($good_course as $v){
			$tmp[]=$course_type[$v];
		}
		$data['good_course'] =  implode(',',$tmp);
		
		//页面标签
		$data['page_english_level'] =  Common::_t('english_level');
		$data['page_nationality'] = Common::_t('nationality');
		$data['page_sex']=Common::_t('sex');
		
		$level_list = HttpDaoManager::getLevelDao()->searchList();
		$level_pair = array();
		foreach($level_list as $k=>$v){
			if(isset($v['id'])){
				$level_pair[$v['id']]='Level'.'-'.$v['level'];
			}
		}
		unset($level_list);
		$data['level_pair'] = $level_pair;
		
		return $data;
	}
	public function courseArrangement(){
		$data['time'] = Common::getTimes();
		$page= getParamValue('page');
		$data['date'] = HttpServerManager::getTeacherStartCourseServer()->weeksTimeStamps($page);
		$data['courseTimeData'] = HttpServerManager::getTeacherStartCourseServer()->getCourseTimeByData($data['date'],Common::getGetStrValue('teacherId'));
		
		return $data;
	}

	public function courseArrangementManager(){
		$data['time'] = Common::getTimes();
		$page= getParamValue('page');
		$data['date'] = HttpServerManager::getTeacherStartCourseServer()->weeksTimeStampsManager($page);
		$data['courseTimeData'] = HttpServerManager::getTeacherStartCourseServer()->getCourseTimeByData($data['date'],Common::getGetStrValue('teacherId'));
	
		return $data;
	}
	
	public function startCourse(){
		$tmp =explode('-',$_POST['time']);
		HttpServerManager::getTeacherStartCourseServer()->startCourse($tmp[0],$tmp[1], $_POST['type'],Common::getPostStrValue('teacherId'));
	}
	public function startAllCourse(){
		$time_list =$_POST['time_list'];
		HttpServerManager::getTeacherStartCourseServer()->startAllCourse($time_list, $_POST['type'],Common::getPostStrValue('teacherId'));
	}
	public function saveConfirmAllCourse(){
		$time_list =$_POST['time_list'];
		HttpServerManager::getTeacherStartCourseServer()->saveConfirmAllCourse($time_list, $_POST['type'],Common::getPostStrValue('teacherId'));
	}
	public function course(){
		if (!isset($_GET['m'])){
			$y = date('Y');
			$m = date('m');
		}
		else{
			$y = date('Y',$_GET['m']);
			$m = date('m',$_GET['m']);
		}
		$nextM = $m+1;
		$nextY = $y;
		if ($nextM>12){
			$nextM = 1;
			$nextY = $nextY+1;
		}
		$nextTime = strtotime($nextY.'-'.$nextM);
		$upY = $y;
		$upM = $m-1;
		if ($upM==0){
			$upM = 12;
			$upY = $upY-1;
		}
		$upTime = strtotime($upY.'-'.$upM);
		$date = isset($_GET['date'])?$_GET['date']:strtotime(date('Y-m-d'));
		$data['calendar'] = ClassManager::getCalendar()->display1($y,$m,$date);
		$teacher_id = Common::getGetStrValue('teacherId');
		$get_teacher_id=$_GET['teacherId'];
		if($_SESSION['admin']['teacher_id']!=0){
	  		$teacher_id = $_SESSION['admin']['teacher_id'];
	 	}
		if(isset($get_teacher_id)&&$get_teacher_id>0){
	  		$teacher_id = $get_teacher_id;
		}
		$data['y']=$y;
		$data['m']=$m;
		$data['upTime'] = $upTime;
		$data['nextTime'] = $nextTime;
		$data['time'] = Common::getTimes();
		$page= getParamValue('page');
		$data['date'] = HttpServerManager::getTeacherStartCourseServer()->weeksTimeStamps($page,0,$date);
		$data['courseTimeData'] = HttpServerManager::getTeacherStartCourseServer()->getCourseTimeByData($data['date'],$teacher_id);
		return $data;
	}
}
?>